<template>
  <div class="table-wrapper">
    <div class="search-container">
      <div class="search-wrapper">
        <span class="label">校区：</span>
        <el-select size="mini" v-model="params.is_xq" placeholder="请选择校区" @change="getBuilde" clearable>
          <el-option v-for="item in xqList" :key="item.text" :label="item.text" :value="item.value"></el-option>
        </el-select>
      </div>
      <div class="search-wrapper">
        <span class="label">楼宇：</span>
        <el-cascader size="mini" class="large-select" v-model="params.build_id" :options="buildingList" placeholder="请选择楼宇"
                     :props="{ checkStrictly: true, emitPath: false, multiple: false }"
                     :disabled="!params.is_xq"
                     collapse-tags
                     clearable>
        </el-cascader>
      </div>
      <div class="search-wrapper">
        <span class="label">设备名称：</span>
        <el-input v-model="params.name" size="mini" class="common-input" placeholder="请输入设备名称"></el-input>
      </div>
      <div class="search-wrapper">
        <span class="label">设备分类：</span>
        <el-select size="mini" v-model="params.class_id" placeholder="请选择设备分类" clearable>
          <el-option v-for="item in equipmentList" :key="item.name" :label="item.name" :value="item.id"></el-option>
        </el-select>
      </div>
      <div class="search-wrapper">
        <el-button @click="getEquipment" icon="el-icon-search" size="mini" >查询</el-button>
      </div>
    </div>
    <el-table
      :data="data"
      border
      height="calc(100% - 100px)"
      style="width: 100%">
      <el-table-column
        prop="builde_name"
        label="楼宇名称">
      </el-table-column>
      <el-table-column
        prop="name"
        label="设备名称">
      </el-table-column>
      <el-table-column
        prop="brand"
        label="设备品牌"
        width="100">
      </el-table-column>
      <el-table-column
        prop="model"
        label="设备型号">
      </el-table-column>
      <el-table-column
        prop="code"
        label="设备代号">
      </el-table-column>
      <el-table-column
        prop="quantity"
        label="数量"
        width="60">
      </el-table-column>
      <el-table-column
        prop="address"
        label="安装地点">
      </el-table-column>
      <el-table-column
        prop="put_time"
        label="投入时间"
        width="100">
      </el-table-column>
      <el-table-column
        prop="wbcj"
        label="维保厂家">
      </el-table-column>
      <el-table-column
        prop="des"
        label="设备备注">
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import portal from '@/api/portal'

export default {
  name: 'SbList',
  data () {
    return {
      params: {
        build_id: [],
        page: 1,
        total: 0,
        id: null,
        name: null,
        class_id: null
      },
      xqList: [
        {
          text: '中关村',
          value: 1
        },
        {
          text: '良乡',
          value: 2
        }
      ],
      buildingList: [],
      equipmentList: [],
      data: []
    }
  },
  created () {
    this.getEquipmentClass()
  },
  computed: {
  },
  mounted () {
  },
  methods: {
    // 工程列表
    async getEquipment () {
      const params = {
        id: this.params.build_id,
        name: this.params.name,
        class_id: this.params.class_id,
        page: this.params.page
      }
      if (!this.params.is_xq) {
        this.$message.warning('请选择校区')
        return
      }
      const result = await portal.getEquipment(params)
      if (result.data) {
        this.data = result.data
      }
    },
    // 根据校区获取楼宇
    async getBuilde () {
      const params = {
        is_xq: this.params.is_xq
      }
      const result = await portal.getBuilde(params)
      if (result.data) {
        const buildAddresss = result.data
        buildAddresss.forEach(e => {
          e.value = e.id
          e.label = e.builde_name
          e.check = false
        })
        this.buildingList = buildAddresss
      }
    },
    // 设备分类获取
    async getEquipmentClass () {
      const result = await portal.getEquipmentClass()
      if (result.data) {
        this.equipmentList = result.data
      }
    }
  }
}
</script>

<style scoped lang="scss">

</style>
